Processing math: 100%

runge_kutta_45 Derived Type

type, public, extends(single_step_integrator) :: runge_kutta_45

The Dormand-Prince, Runge-Kutta integrator (5th order, with an embedded 4th order used for error estimation).


Type-Bound Procedures

procedure, public :: append_to_buffer => oi_append_to_buffer

Appends the supplied solution point to the internal solution buffer.

  • private subroutine oi_append_to_buffer(this, x, y, err)

    Appends the supplied solution point to the internal solution buffer.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The independent variable value.

    real(kind=real64), intent(in), dimension(:) :: y

    The values of the dependent variables corresponding to x.

    class(errors), intent(inout), optional, target :: err

    An optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.

    • DIFFEQ_MEMORY_ALLOCATION_ERROR: Occurs if there is a memory allocation issue.

procedure, public :: attempt_step => rk45_attempt_step

Attempts an integration step for this integrator.

  • private subroutine rk45_attempt_step(this, sys, h, x, y, f, yn, fn, yerr, k)

    Attempts an integration step for this integrator.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(inout) :: this

    The runge_kutta_45 object.

    class(ode_container), intent(inout) :: sys

    The ode_container object containing the ODE's to integrate.

    real(kind=real64), intent(in) :: h

    The current step size.

    real(kind=real64), intent(in) :: x

    The current value of the independent variable.

    real(kind=real64), intent(in), dimension(:) :: y

    An N-element array containing the current solution at x.

    real(kind=real64), intent(in), dimension(:) :: f

    An N-element array containing the values of the derivatives at x.

    real(kind=real64), intent(out), dimension(:) :: yn

    An N-element array where this routine will write the next solution estimate at x + h.

    real(kind=real64), intent(out), dimension(:) :: fn

    An N-element array where this routine will write the next derivative estimate at x + h.

    real(kind=real64), intent(out), dimension(:) :: yerr

    An N-element array where this routine will write an estimate of the error in each equation.

    real(kind=real64), intent(out), dimension(:,:) :: k

    An N-by-NSTAGES matrix containing the derivatives at each stage.

procedure, public :: clear_buffer => oi_clear_buffer

Clears the contents of the buffer.

  • private subroutine oi_clear_buffer(this)

    Clears the contents of the buffer.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

procedure, public :: compute_error_norm => oi_estimate_error

Computes the norm of the scaled error estimate.

  • private pure function oi_estimate_error(this, y, yest, yerr) result(rst)

    Computes the norm of the scaled error estimate. A value less than one indicates a successful step. A value greater than one suggests that the results do not meet the requested tolerances.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    real(kind=real64), intent(in), dimension(:) :: y

    The previously accepted solution array (N-element).

    real(kind=real64), intent(in), dimension(size(y)) :: yest

    An N-element array containing the next solution point estimate.

    real(kind=real64), intent(in), dimension(size(y)) :: yerr

    An N-element array containing the estimate of error for each equation.

    Return Value real(kind=real64)

    The norm of the scaled error.

procedure, public :: estimate_inital_step_size => oi_initial_step

Computes an estimate of an initial step size.

  • private pure subroutine oi_initial_step(this, sys, xo, xf, yo, fo, h)

    Computes an estimate of an initial step size.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    class(ode_container), intent(in) :: sys

    The ode_container object containing the ODE's to integrate.

    real(kind=real64), intent(in) :: xo

    The initial value of the independent variable.

    real(kind=real64), intent(in) :: xf

    The final value of the independent variable.

    real(kind=real64), intent(in), dimension(:) :: yo

    The initial values of the dependent variables (N-element).

    real(kind=real64), intent(out), dimension(size(yo)) :: fo

    An N-element array where the function values at xo will be written.

    real(kind=real64), intent(out) :: h

    The initial step size estimate.

procedure, public :: estimate_next_step_size => oi_next_step

Estimates the next step size.

  • private function oi_next_step(this, e, eold, h, x, err) result(rst)

    Estimates the next step size based upon the current and previous error estimates.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: e

    The norm of the current scaled error estimate.

    real(kind=real64), intent(inout) :: eold

    The norm of the previous step's scaled error estimate. On output, this variable is updated.

    real(kind=real64), intent(in) :: h

    The current step size.

    real(kind=real64), intent(in) :: x

    The current independent variable value.

    class(errors), intent(inout), optional, target :: err

    An optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.

    • DIFFEQ_STEP_SIZE_TOO_SMALL_ERROR: Occurs if the step size becomes too small in magnitude.

    Return Value real(kind=real64)

    The new step size estimate.

procedure, public :: get_absolute_tolerance => oi_get_abs_tol

Gets the absolute error tolerance.

  • private pure function oi_get_abs_tol(this) result(rst)

    Gets the absolute error tolerance.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The tolerance value.

procedure, public :: get_allow_overshoot => oi_get_allow_overshoot

Gets a value determining if the solver is allowed to overshoot the final value in the integration range.

  • private pure function oi_get_allow_overshoot(this) result(rst)

    Gets a value determining if the solver is allowed to overshoot the final value in the integration range.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value logical

    True if the solver can overshoot, and then interpolate to achieve the required final value; else, false thereby indicating the solver cannot overshoot.

procedure, public :: get_is_fsal => rk45_get_is_fsal

Gets a logical parameter stating if this is a first-same-as-last (FSAL) integrator.

  • private pure function rk45_get_is_fsal(this) result(rst)

    Gets a logical parameter stating if this is a first-same-as-last (FSAL) integrator.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(in) :: this

    The runge_kutta_45 object.

    Return Value logical

    True for a FSAL integrator; else, false.

procedure, public :: get_maximum_step_size => oi_get_max_step

Gets the magnitude of the maximum allowed step size.

  • private pure function oi_get_max_step(this) result(rst)

    Gets the magnitude of the maximum allowed step size.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The step size limit.

procedure, public :: get_minimum_step_size => oi_get_min_step

Gets the magnitude of the minimum allowed step size.

  • private pure function oi_get_min_step(this) result(rst)

    Gets the magnitude of the minimum allowed step size.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The step size limit.

procedure, public :: get_order => rk45_get_order

Gets the order of the integrator.

  • private pure function rk45_get_order(this) result(rst)

    Gets the order of the integrator.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(in) :: this

    The runge_kutta_45 object.

    Return Value integer(kind=int32)

    The order.

procedure, public :: get_relative_tolerance => oi_get_abs_tol

Gets the relative error tolerance.

  • private pure function oi_get_abs_tol(this) result(rst)

    Gets the absolute error tolerance.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The tolerance value.

procedure, public :: get_solution => oi_get_solution

Returns the solution computed by the integrator.

  • private pure function oi_get_solution(this) result(rst)

    Returns the solution computed by the integrator stored as a matrix with the first column containing the values of the independent variable at which the solution was computed. The remaining columns contain the solutions for each of the integrated equations in the order in which they appear in the source routine. Notice, the solve routine must be called before this routine.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64), allocatable, dimension(:,:)

    The resulting solution matrix.

procedure, public :: get_stage_count => rk45_get_stage_count

Gets the stage count for this integrator.

  • private pure function rk45_get_stage_count(this) result(rst)

    Gets the stage count for this integrator.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(in) :: this

    The runge_kutta_45 object.

    Return Value integer(kind=int32)

    The stage count.

procedure, public :: get_step_limit => oi_get_step_limit

Gets the limit on the number of integration steps.

  • private pure function oi_get_step_limit(this) result(rst)

    Gets the limit on the number of integration steps that may be taken before the solver terminates.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value integer(kind=int32)

    The step limit.

procedure, public :: get_step_size_control_parameter => oi_get_control_parameter

Gets the step size PI control parameter.

  • private pure function oi_get_control_parameter(this) result(rst)

    Gets the step size control parameter β used for PI control of the step size. A value of 0 provides a default step size controller (non-PI); however, a nonzero value of β provides PI control that improves stability, but comes with a potential for efficiency loss. A good estimate for a starting point for this parameter is β=0.4k where k is the order of the integrator.

    The PI controller for step size is defined as follows. hn+1=fshneαneβn1

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The control parameter.

procedure, public :: get_step_size_factor => oi_get_safety_factor

Gets the step size safety factor.

  • private pure function oi_get_safety_factor(this) result(rst)

    Gets the safety factor (step size multiplier) used to provide a measure of control to the step size estimate such that hnew=fsh, where fs is this safety factor.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(in) :: this

    The ode_integrator object.

    Return Value real(kind=real64)

    The safety factor.

procedure, public :: interpolate => rk45_interp

Performs the interpolation.

  • private subroutine rk45_interp(this, x, xn, yn, fn, xn1, yn1, fn1, y)

    Performs the interpolation.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(in) :: this

    The runge_kutta_45 object.

    real(kind=real64), intent(in) :: x

    The value of the independent variable at which to compute the interpolation.

    real(kind=real64), intent(in) :: xn

    The previous value of the independent variable at which the solution is computed.

    real(kind=real64), intent(in), dimension(:) :: yn

    An N-element array containing the solution at xn.

    real(kind=real64), intent(in), dimension(:) :: fn

    An N-element array containing the derivatives at xn.

    real(kind=real64), intent(in) :: xn1

    The value of the independent variable at xn + h.

    real(kind=real64), intent(in), dimension(:) :: yn1

    An N-element array containing the solution at xn + h.

    real(kind=real64), intent(in), dimension(:) :: fn1

    An N-element array containing the derivatives at xn + h.

    real(kind=real64), intent(out), dimension(:) :: y

    An N-element array where this routine will write the solution values interpolated at x.

procedure, public :: post_step_action => rk45_set_up_interp

Sets up the interpolation process as the post-step action.

  • private subroutine rk45_set_up_interp(this, sys, dense, x, xn, y, yn, f, fn, k)

    Sets up the interpolation process.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(inout) :: this

    The runge_kutta_45 object.

    class(ode_container), intent(inout) :: sys

    The ode_container object containing the ODE's to integrate.

    logical, intent(in) :: dense

    Determines if dense output is requested (true); else, false.

    real(kind=real64), intent(in) :: x

    The previous value of the independent variable.

    real(kind=real64), intent(in) :: xn

    The current value of the independent variable.

    real(kind=real64), intent(in), dimension(:) :: y

    An N-element array containing the solution at x.

    real(kind=real64), intent(in), dimension(:) :: yn

    An N-element array containing the solution at xn.

    real(kind=real64), intent(in), dimension(:) :: f

    An N-element array containing the derivatives at x.

    real(kind=real64), intent(in), dimension(:) :: fn

    An N-element array containing the derivatives at xn.

    real(kind=real64), intent(inout), dimension(:,:) :: k

    An N-by-NSTAGES matrix containing the derivatives at each stage.

procedure, public :: pre_step_action => rk45_pre_step

Performs any pre-step actions.

  • private subroutine rk45_pre_step(this, prevs, sys, h, x, y, f, err)

    Placeholder routine for any pre-step actions.

    Arguments

    Type IntentOptional Attributes Name
    class(runge_kutta_45), intent(inout) :: this

    The runge_kutta_45 object.

    logical, intent(in) :: prevs

    Defines the status of the previous step. The value is true if the previous step was successful; else, false if the previous step failed.

    class(ode_container), intent(inout) :: sys

    The ode_container object containing the ODE's to integrate.

    real(kind=real64), intent(in) :: h

    The current step size.

    real(kind=real64), intent(in) :: x

    The current value of the independent variable.

    real(kind=real64), intent(in), dimension(:) :: y

    An N-element array containing the current solution at x.

    real(kind=real64), intent(in), dimension(:) :: f

    An N-element array containing the values of the derivatives at x.

    class(errors), intent(inout), optional, target :: err

    An optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling.

procedure, public :: set_absolute_tolerance => oi_set_abs_tol

Sets the absolute error tolerance.

  • private subroutine oi_set_abs_tol(this, x)

    Sets the absolute error tolerance.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The tolerance value.

procedure, public :: set_allow_overshoot => oi_set_allow_overshoot

Sets a value determining if the solver is allowed to overshoot the final value in the integration range.

  • private subroutine oi_set_allow_overshoot(this, x)

    Sets a value determining if the solver is allowed to overshoot the final value in the integration range.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    logical, intent(in) :: x

    True if the solver can overshoot, and then interpolate to achieve the required final value; else, false thereby indicating the solver cannot overshoot.

procedure, public :: set_maximum_step_size => oi_set_max_step

Sets the magnitude of the maximum allowed step size.

  • private subroutine oi_set_max_step(this, x)

    Sets the magnitude of the maximum allowed step size.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The step size limit.

procedure, public :: set_minimum_step_size => oi_set_min_step

Sets the magnitude of the minimum allowed step size.

  • private subroutine oi_set_min_step(this, x)

    Sets the magnitude of the minimum allowed step size.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The step size limit.

procedure, public :: set_relative_tolerance => oi_set_abs_tol

Sets the relative error tolerance.

  • private subroutine oi_set_abs_tol(this, x)

    Sets the absolute error tolerance.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The tolerance value.

procedure, public :: set_step_limit => oi_set_step_limit

Sets the limit on the number of integration steps.

  • private subroutine oi_set_step_limit(this, x)

    Sets the limit on the number of integration steps that may be taken before the solver terminates.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    integer(kind=int32), intent(in) :: x

    The step limit.

procedure, public :: set_step_size_control_parameter => oi_set_control_parameter

Sets the step size PI control parameter.

  • private subroutine oi_set_control_parameter(this, x)

    Sets the step size control parameter β used for PI control of the step size. A value of 0 provides a default step size controller (non-PI); however, a nonzero value of β provides PI control that improves stability, but comes with a potential for efficiency loss. A good estimate for a starting point for this parameter is β=0.4k where k is the order of the integrator.

    The PI controller for step size is defined as follows. hn+1=fshneαneβn1

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The control parameter

procedure, public :: set_step_size_factor => oi_set_safety_factor

Sets the step size safety factor.

  • private subroutine oi_set_safety_factor(this, x)

    Sets the safety factor (step size multiplier) used to provide a measure of control to the step size estimate such that hnew=fsh, where fs is this safety factor.

    Arguments

    Type IntentOptional Attributes Name
    class(ode_integrator), intent(inout) :: this

    The ode_integrator object.

    real(kind=real64), intent(in) :: x

    The safety factor.

procedure, public :: solve => ssi_ode_solver

Solves the supplied system of ODE's.

  • private subroutine ssi_ode_solver(this, sys, x, iv, err)

    Solves the supplied system of ODE's.

    Arguments

    Type IntentOptional Attributes Name
    class(single_step_integrator), intent(inout) :: this

    The single_step_integrator object.

    class(ode_container), intent(inout) :: sys

    The ode_container object containing the ODE's to integrate.

    real(kind=real64), intent(in), dimension(:) :: x

    An array of independent variable values at which to return the the solution to the ODE's.

    real(kind=real64), intent(in), dimension(:) :: iv

    An array containing the initial values for each ODE.

    class(errors), intent(inout), optional, target :: err

    An optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.

    • DIFFEQ_MEMORY_ALLOCATION_ERROR: Occurs if there is a memory allocation issue.

    • DIFFEQ_NULL_POINTER_ERROR: Occurs if no ODE function is defined.

    • DIFFEQ_ARRAY_SIZE_ERROR: Occurs if there are less than 2 values given in the independent variable array x.